package live.jialing.sip.base.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.google.common.collect.Lists;
import live.jialing.structure.domain.User;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;
import java.util.List;

/**
 * 家长、监护人
 */
@Setter
@Getter
@ToString
@Entity
@DiscriminatorValue("parent")
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id",scope = Parent.class)
public class Parent extends User {

    /**
     * 孩子
     */
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "base_family",
            inverseJoinColumns = {@JoinColumn(name = "child_id", referencedColumnName = "id") },
            joinColumns = { @JoinColumn(name = "parent_id", referencedColumnName = "id") })
    private List<Child> children = Lists.newArrayList();

}
